//
//  UIAlertController+Category.m
//  Project_Demo
//
//  Created by caoxiaozhu on 2018/7/4.
//  Copyright © 2018年 caoxiaozhu. All rights reserved.
//

#import "UIAlertController+Category.h"

@implementation UIAlertController (Category)

+(UIAlertController *)alertWithTitle:(NSString *)title Message:(NSString *)message buttonNum:(NSInteger)num buttonTitle:(NSArray*)btnArr actionBlock:(void(^)(int flag))actionBlock{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    for (int i = 0; i<num; i++) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:btnArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            actionBlock(i);
        }];
        [alertVc addAction: action];
    }
    
    return alertVc;
}


+(UIAlertController *)alertWithTitle:(NSString *)title Message:(NSString *)message LetfTitle:(NSString *)leftStr RightTitle:(NSString *)rightStr LeftColor:(UIColor *)leftColor RightColor:(UIColor *)rightColor  LeftBlock:(void(^)(void))leftBlock RightBlock:(void (^)(void))rightBlock{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *leftAction = [UIAlertAction actionWithTitle:leftStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        leftBlock();
    }];
    
    UIAlertAction *rightAction = [UIAlertAction actionWithTitle:rightStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        rightBlock();
    }];
    
    //颜色
    if (leftColor) {
        [leftAction setValue: leftColor forKey:@"titleTextColor"];
    }
    
    if (rightColor) {
        [rightAction setValue: rightColor forKey:@"titleTextColor"];
    }
    
    [alertVc addAction:leftAction];
    [alertVc addAction:rightAction];
    
    return alertVc;
}


+(UIAlertController *)alertSheetWithTitle:(NSString *)title Message:(NSString *)message buttonNum:(NSInteger)num buttonTitle:(NSArray*)btnArr actionBlock:(void(^)(int flag))actionBlock{
    
    UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    
    for (int i = 0; i<num; i++) {
        UIAlertAction *action = [UIAlertAction actionWithTitle:btnArr[i] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            actionBlock(i);
        }];
        [alertVc addAction: action];
    }
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [cancelAction setValue:[UIColor redColor] forKey:@"titleTextColor"];
    [alertVc addAction:cancelAction];
    
    return alertVc;
}


@end
